package com.atguigu.controller;


import com.atguigu.pojo.Account;
import com.atguigu.service.AccountService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("updateAccount")
    public String updateAccount(@RequestBody Account account){
        System.out.println("account = " + account);
        accountService.updateAccount(account);
        return "修改成功";
    }


    @RequestMapping("queryAccountById")
    public Account queryAccountById(Integer id){
        Account account = accountService.queryAccountById(id);
        return account;
    }

    @RequestMapping("saveAccount")
    public String saveAccount(@RequestBody Account account){
        accountService.saveAccount(account);
        return "新增成功";
    }


    @RequestMapping("deleteAccountById")
    public String deleteAccountById(Integer id){
        accountService.deleteAccountById(id);
        return "删除成功";
    }


    @RequestMapping("queryAccountByPage")
    public PageInfo<Account> queryAccountByPage(Integer currentPage){
        if(currentPage == null)
            currentPage = 1;
        int pageSize = 5;
        PageInfo<Account> pageInfo = accountService.queryAccountByPage(currentPage, pageSize);
        //System.out.println("pageInfo = " + pageInfo);
        return pageInfo;
    }
}
